

package com.mt.restaurant.controller.material;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.mt.restaurant.dto.material.OrderMaterialRelationEditDto;
import com.mt.restaurant.entity.material.OrderMaterialRelation;
import com.mt.restaurant.service.material.OrderMaterialRelationService;


@Api(tags = "订单材料关系")
@RestController
@RequestMapping("/api/restaurant/material/OrderMaterialRelation")
@CrossOrigin(allowCredentials = "true")
public class OrderMaterialRelationController {
    private static Logger logger = LoggerFactory.getLogger(OrderMaterialRelationController.class);


    @Autowired
    private OrderMaterialRelationService orderMaterialRelationService;

    /**
     * 根据分页参数查询订单材料关系集合
     *
     * @param pageDTO 分页条件
     */
//    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("分页查询订单材料关系")
    @ApiPageParam
    @PostMapping("/findOrderMaterialRelations")
    public PageResultDTO findOrderMaterialRelations(@RequestBody PageDTO pageDTO) {
        return this.orderMaterialRelationService.findOrderMaterialRelations(pageDTO);
    }

    /**
     * 根据ID查询指定的订单材料关系
     *
     * @param orderMaterialRelationId Id
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("根据id查询订单材料关系")
    @ApiPageParam
    @PostMapping("/findOrderMaterialRelation")
    public OrderMaterialRelation findOrderMaterialRelation(@RequestParam Long orderMaterialRelationId) {
        return this.orderMaterialRelationService.findOrderMaterialRelation(orderMaterialRelationId);
    }

    /**
     * 根据ID查询指定的订单材料关系(包含外键名称)
     *
     * @param orderMaterialRelationId Id
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("根据ID查询指定的订单材料关系(包含外键名称)")
    @PostMapping("/findOrderMaterialRelationForView")
    public OrderMaterialRelation findOrderMaterialRelationForView(@RequestParam Long orderMaterialRelationId) {
        return this.orderMaterialRelationService.findOrderMaterialRelationWithForeignName(orderMaterialRelationId);
    }

    /**
     * 根据ID查询指定的订单材料关系(包含订单材料关系和外键名称)
     *
     * @param orderMaterialRelationId Id
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("根据ID查询指定的订单材料关系(包含订单材料关系和外键名称)")
    @PostMapping("/findOrderMaterialRelationForEdit")
    public OrderMaterialRelationEditDto findOrderMaterialRelationForEdit(@RequestParam Long orderMaterialRelationId) {
        OrderMaterialRelationEditDto orderMaterialRelationEditDto = new OrderMaterialRelationEditDto();
        orderMaterialRelationEditDto.setOrderMaterialRelation(this.orderMaterialRelationService.findOrderMaterialRelationWithForeignName(orderMaterialRelationId));

        this.prepareOrderMaterialRelationEditDto(orderMaterialRelationEditDto);

        return orderMaterialRelationEditDto;
    }

    /**
     * 根据ID查询指定的订单材料关系(只提取ID 和 Name)
     *
     * @param orderMaterialRelationId Id
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("根据ID查询指定的订单材料关系(只提取ID 和 Name)")
    @PostMapping("/findOrderMaterialRelationsWithIdNameById")
    public OrderMaterialRelation findOrderMaterialRelationsWithIdNameById(@RequestParam Long orderMaterialRelationId) {
        return this.orderMaterialRelationService.findOrderMaterialRelationsWithIdNameById(orderMaterialRelationId);
    }

    /**
     * 根据名称查询订单材料关系集合(只提取ID 和 Name)
     *
     * @param orderMaterialRelationName 名称
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:view')")
    @ApiOperation("根据名称查询订单材料关系集合(只提取ID 和 Name)")
    @PostMapping("/findOrderMaterialRelationsWithIdNameByName")
    public List<OrderMaterialRelation> findOrderMaterialRelationsWithIdNameByName(@RequestParam String orderMaterialRelationName) {
        return this.orderMaterialRelationService.findOrderMaterialRelationsWithIdNameByName(orderMaterialRelationName);
    }


    /**
     * 创建新的订单材料关系
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:add')")
    @ApiOperation("创建新的订单材料关系")
    @PostMapping("/createOrderMaterialRelation")
    public OrderMaterialRelationEditDto createOrderMaterialRelation() {
        OrderMaterialRelationEditDto orderMaterialRelationEditDto = new OrderMaterialRelationEditDto();
        orderMaterialRelationEditDto.setOrderMaterialRelation(new OrderMaterialRelation());

        this.prepareOrderMaterialRelationEditDto(orderMaterialRelationEditDto);
        return orderMaterialRelationEditDto;
    }

    private void prepareOrderMaterialRelationEditDto(OrderMaterialRelationEditDto orderMaterialRelationEditDto) {
    }

    /**
     * 新增保存订单材料关系
     *
     * @param orderMaterialRelation 实体对象
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:add')")
    @ApiOperation("新增保存订单材料关系")
    @PostMapping("/saveOrderMaterialRelation")
    public OrderMaterialRelation saveOrderMaterialRelation(@RequestBody OrderMaterialRelation orderMaterialRelation) {
        return this.orderMaterialRelationService.saveOrderMaterialRelation(orderMaterialRelation);
    }

    /**
     * 修改保存订单材料关系
     *
     * @param orderMaterialRelation 实体对象
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:update')")
    @ApiOperation("修改保存订单材料关系")
    @PostMapping("/updateOrderMaterialRelation")
    public OrderMaterialRelation updateOrderMaterialRelation(@RequestBody OrderMaterialRelation orderMaterialRelation) {
        return this.orderMaterialRelationService.updateOrderMaterialRelation(orderMaterialRelation);
    }

    /**
     * 修改保存订单材料关系状态
     *
     * @param orderMaterialRelations 实体对象
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:update')")
    @ApiOperation("修改保存订单材料关系")
    @PostMapping("/updateOrderMaterialRelationStatus")
    public OrderMaterialRelation updateOrderMaterialRelationStatus(@RequestBody List<OrderMaterialRelation> orderMaterialRelations) {
        return this.orderMaterialRelationService.updateOrderMaterialRelationStatus(orderMaterialRelations);
    }

    /**
     * 根据ID删除订单材料关系
     *
     * @param orderMaterialRelationId ID
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:remove')")
    @ApiOperation("根据ID删除订单材料关系")
    @PostMapping("/deleteOrderMaterialRelation")
    public void deleteOrderMaterialRelation(@RequestParam Long orderMaterialRelationId) {
        this.orderMaterialRelationService.deleteOrderMaterialRelation(orderMaterialRelationId);
    }

    /**
     * 根据ID退货
     *
     * @param orderMaterialRelationId ID
     */
    @PreAuthorize("hasAuthority('restaurant:material:OrderMaterialRelation:remove')")
    @ApiOperation("根据ID删除订单材料关系")
    @PostMapping("/returnOrderMaterial")
    public void returnOrderMaterial(@RequestParam Long orderMaterialRelationId) {
        this.orderMaterialRelationService.returnOrderMaterial(orderMaterialRelationId);
    }


}

